package com.xsm.ppsecret.sql;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;

import com.xsm.ppsecret.App;

/**
 * Author: Xiasem
 * Email: xiasem@163.com
 * Date: 17-1-6.
 */

public class PPUserSql {

    public static boolean savePwdEntry(SQLiteDatabase database, String json) {
        boolean ret = false;
        if (json != null && !json.isEmpty()) {
            ContentValues values = new ContentValues();
            values.put(DataContracts.PWDS.JSON, json);
            values.put(DataContracts.PWDS.AUTHORITY, App.getInstance().authority);
            database.insert(DataContracts.PWDS.TABLE_NAME, null, values);
            ret = true;
        }
        return ret;
    }

    public static boolean saveLogEntry(SQLiteDatabase database, String json) {
        boolean ret = false;
        if (json != null && !json.isEmpty()) {
            ContentValues values = new ContentValues();
            values.put(DataContracts.LOGS.JSON, json);
            values.put(DataContracts.LOGS.AUTHORITY, App.getInstance().authority);
            database.insert(DataContracts.LOGS.TABLE_NAME, null, values);
            ret = true;
        }
        return ret;
    }

    public static int updateLogEntry(SQLiteDatabase database, String str, int id) {
        ContentValues values = new ContentValues();
        values.put(DataContracts.LOGS.JSON, str);
        values.put(DataContracts.LOGS.AUTHORITY, App.getInstance().authority);
        return database.update(DataContracts.LOGS.TABLE_NAME, values, "_id=?", new String[]{String.valueOf(id)});
    }
}
